//
//  Constans.h
//  WeKeTang
//
//  Created by ichina on 2017/8/21.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#ifndef Constans_h
#define Constans_h

#import <MJExtension/MJExtension.h>
#import <Masonry.h>
#import <SVProgressHUD.h>
#import <MBProgressHUD/MBProgressHUD.h>
#import <YYKit.h>
#import "BaseEngine.h"
#import "UIColor+KZExtension.h"
#import "UMMobClick/MobClick.h"

typedef NS_ENUM(NSInteger, DownloadVideoState){
    DownloadVideoStateDownloading = 1,
    DownloadVideoStateWating = 2,
    DownloadVideoStatePausing = 3,
    DownloadVideoStateFail = 4,
    DownloadVideoStateFinish = 5,
};

typedef NS_ENUM(NSInteger, M3U8AnalyseFail){
    M3U8AnalyseFailNotM3U8Url = 1,
    M3U8AnalyseFailNetworkUnConnection = 2,
};
//判断是iPhone 还是 iPad
#define isPhone ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define kPathDownload    @"DownloadVideos"
#define kTestDownloadingFileSuffix @"_etc"
#define kDownloadVideoId @"TTT"

#define theApp          ((AppDelegate *)[[UIApplication sharedApplication] delegate])
//屏幕视图尺寸
#define kDeviceScreenSize [UIScreen mainScreen].bounds.size
#define kDeviceScreenBounds   [UIScreen mainScreen].bounds
#define kDeviceScreenWidth        [UIScreen mainScreen].bounds.size.width
#define kDeviceScreenHeight       [UIScreen mainScreen].bounds.size.height
#define kStatusHeight   [UIApplication sharedApplication].statusBarFrame.size.height
#define kNavigationHeight   44.0
#define kTabBarHeight          49.0
#define kMainViewHeight    (kDeviceScreenHeight - kNavigationHeight)
#define kDeviceWidthScale   (kDeviceScreenWidth / 375.0)
#define kDeviceHeightScale  (kDeviceScreenHeight / 667)
#define kUserDefaults      [NSUserDefaults standardUserDefaults]

#define IsExist_String(_str) (_str!=nil && _str.length!=0 && ![_str isEqualToString:@""])
#define isExistString(_str) (_str == nil || _str.length == 0 || [_str isEqualToString:@""])
//取得指定名称的图片
#define IMG(name) [UIImage imageNamed:name]
#define _S(str,...) [NSString stringWithFormat:str,##__VA_ARGS__]
#define URL(str) [NSURL URLWithString:str]
//颜色
#define RGBColor(r,g,b) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1]

//识别设备
#define iPhone7Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhone7 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || (CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)&&CGSizeEqualToSize(CGSizeMake(375, 667), [[UIScreen mainScreen] bounds].size))) : NO)

#define iPhone6sPlus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhone6s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || (CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)&&CGSizeEqualToSize(CGSizeMake(375, 667), [[UIScreen mainScreen] bounds].size))) : NO)

#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || (CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)&&CGSizeEqualToSize(CGSizeMake(375, 667), [[UIScreen mainScreen] bounds].size))) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)

//静态内敛函数
CG_INLINE CGRect WTCGRectMake(CGRect frame){
    
    CGRect rect;
    CGFloat heightConsult = (kDeviceScreenHeight-kStatusHeight-kNavigationHeight)/603;
    CGFloat widthConsult = (kDeviceScreenWidth)/375;
    
    if (frame.size.height == 667 - kNavigationHeight - kStatusHeight) {
        heightConsult = (kDeviceScreenHeight-kNavigationHeight-kStatusHeight)/603;
    }else if (frame.size.height == 667){
        heightConsult = kDeviceScreenHeight/667;
    }
    
    if (!iPhone4 && (frame.size.width*heightConsult - kDeviceScreenWidth) < 1 && (frame.size.height*heightConsult == kDeviceScreenHeight || frame.size.height*heightConsult == kDeviceScreenHeight-kNavigationHeight-kStatusHeight)) {
        CGRect rect = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width*widthConsult, frame.size.height*heightConsult);
        return rect;
    }
    
    if (iPhone4) {
        CGFloat consult4 = 568.0/667.0;
        CGPoint center = CGPointMake((frame.origin.x+frame.size.width/2)*consult4, (frame.origin.y+frame.size.height/2)*heightConsult);
        CGFloat _width = frame.size.width*consult4;
        CGFloat _height = frame.size.height*heightConsult;
        rect.origin.x = center.x-_width/2;
        rect.origin.y = center.y-_height/2;
        rect.size.width = _width;
        rect.size.height = _height;
        
    }else{
        
        CGPoint center = CGPointMake((frame.origin.x+frame.size.width/2)*widthConsult, (frame.origin.y+frame.size.height/2)*heightConsult);
        CGFloat _width = frame.size.width*widthConsult;
        CGFloat _height = frame.size.height*heightConsult;
        rect.origin.x = center.x-_width/2;
        rect.origin.y = center.y-_height/2;
        rect.size.width = _width;
        if (frame.size.width == 375.0) {
            rect.size.width = kDeviceScreenWidth;
        }
        if (frame.size.height == 1.0) {
            _height = 1.0;
        }
        if (frame.origin.y + frame.size.height == 603 || frame.origin.y + frame.size.height == 667) {
            if (iPhone6|iPhone6s|iPhone7) {
                _height = _height +10;
            }else if (iPhone6Plus|iPhone6sPlus|iPhone7Plus){
                _height = _height+19;
            }else if (iPhone5){
                
            }
        }
        
        rect.size.height = _height;
    }
    return rect;
}

#endif /* Constans_h */
